package com.hshh.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.hshh.common.CommonUtil;
import com.hshh.common.Constant;
import com.hshh.dao.MemberDAO;

@Controller
@RequestMapping(value={"/member/"})
public class MemberController extends CommonController{
    @Autowired
    MemberDAO memberDAO;

	String TILESForder = "member/";
	/**
	 * 리스트
	 * @return
	 */
	@RequestMapping(value={"list"})
	public String list(Model model, @RequestParam HashMap<String, Object> paramMap, @RequestParam(required=false) Integer pageNum){
		// paging size check
		paramMap = CommonUtil.pageListSizeCheck(paramMap);
		model.addAttribute("pageParam", paramMap);

		// 데이터 size check
		Integer pageDataTotal = memberDAO.selectPagingCount(paramMap);
		model.addAttribute("pageDataTotal", pageDataTotal);

		// 데이터가 있을 경우
    	if(pageDataTotal!=null && pageDataTotal > 0){
	    	model.addAttribute("pagingList", memberDAO.selectPagingList(paramMap, pageNum));
	    }

    	model.addAttribute("roleList", memberDAO.selectCommonCode("user_role"));
    	model.addAttribute("stateList", memberDAO.selectCommonCode("user_state"));
    	
		return TILESForder+"list"+Constant.TILES;
	}

	/**
	 * 상세보기
	 * @return
	 */
	@RequestMapping(value={"view"})
	public String view(){
		return TILESForder+"view"+Constant.TILES;
	}

	/**
	 * 작성 수정
	 * @return
	 */
	@RequestMapping(value={"edit"})
	public String edit(){
		return TILESForder+"edit"+Constant.TILES;
	}
	
	/**
	 * 사용자 등록
	 * @return
	 */
	@RequestMapping(value={"add"})
	public String add(Model model, @RequestParam HashMap<String, Object> paramMap){
		int result = memberDAO.insertMember(paramMap);
		model.addAttribute("code", result - 1);
		return Constant.URL_JSONVIEW;
	}
	
	/**
	 * 사용자 정보 불러오기
	 * @return
	 */
	@RequestMapping(value={"info"})
	public String info(Model model, @RequestParam HashMap<String, Object> paramMap){
		return Constant.URL_JSONVIEW;
	}
}
